import { NestFactory } from '@nestjs/core'
import { AppModule } from './app.module'
import { NestExpressApplication } from '@nestjs/platform-express'
import { join } from 'path'
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger'
import * as cookieParser from 'cookie-parser'
import * as session from 'express-session'

async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule)
  app.setGlobalPrefix('api')
  app.useStaticAssets(join(__dirname, '..', 'upload'), {
    prefix: '/api/upload/', //设置虚拟路径
  })
  app.use(cookieParser())
  app.use(
    session({
      secret: 'secret',
      cookie: { maxAge: 6000 },
    }),
  )
  const config = new DocumentBuilder()
    .setTitle('团圆圆文档')
    .setDescription('团圆圆文档介绍')
    .setVersion('1.0')
    .build()
  const document = SwaggerModule.createDocument(app, config)
  SwaggerModule.setup('document', app, document)
  await app.listen(4000)
}
bootstrap()
